package com.ruoyi.web.controller.yf;

import java.util.List;

import com.mchange.lang.ShortUtils;
import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.system.domain.SysUser;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.yf.domain.YfDeptNurse;
import com.ruoyi.yf.service.IYfDeptNurseService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 科室护士Controller
 *
 * @author XiaoYi...
 * @date 2020-07-06
 * 7941c523-ebb2-4e9e-bc95-9a5a099a7223
 */
@Controller
@RequestMapping("/yf/nurse")
public class YfDeptNurseController extends BaseController {
    private String prefix = "yf/nurse";

    @Autowired
    private IYfDeptNurseService yfDeptNurseService;

    @RequiresPermissions("yf:nurse:view")
    @GetMapping("/{nurseId}")
    public String nurse(@PathVariable("nurseId") String nurseId, ModelMap mmap) {
        mmap.put("nurseId", nurseId);
        return prefix + "/nurse";
    }

    /**
     * 查询科室护士列表
     * 05605fb0-2ef4-48e9-b671-b155ccef03b7
     */
    @RequiresPermissions("yf:nurse:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(YfDeptNurse yfDeptNurse) {
        startPage();
        List<YfDeptNurse> list = yfDeptNurseService.selectYfDeptNurseList(yfDeptNurse);
        return getDataTable(list);
    }

    /**
     * 导出科室护士列表
     * f0106023-89f0-4a1a-b779-434323947c40
     */
    @RequiresPermissions("yf:nurse:export")
    @Log(title = "科室护士", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(YfDeptNurse yfDeptNurse) {
        List<YfDeptNurse> list = yfDeptNurseService.selectYfDeptNurseList(yfDeptNurse);
        ExcelUtil<YfDeptNurse> util = new ExcelUtil<YfDeptNurse>(YfDeptNurse.class);
        return util.exportExcel(list, "nurse");
    }

    /**
     * 新增科室护士
     * 836c4555-d948-4349-bec4-c8cce267ba53
     */
    @GetMapping("/add/{deptId}")
    public String add(@PathVariable("deptId") String deptId, ModelMap mmap) {
        mmap.put("deptId", deptId);
        return prefix + "/add";
    }

    /**
     * 新增保存科室护士
     * 3f4711dd-16c4-4955-af03-db543afb3043
     */
    @RequiresPermissions("yf:nurse:add")
    @Log(title = "科室护士", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(YfDeptNurse yfDeptNurse) {
        SysUser sysUser = ShiroUtils.getSysUser();
        yfDeptNurse.setCreateBy(sysUser.getLoginName());
        yfDeptNurse.setCreateId(sysUser.getUserId());
        return toAjax(yfDeptNurseService.insertYfDeptNurse(yfDeptNurse));
    }

    /**
     * 修改科室护士
     * 490909b6-b216-4593-8e5d-30ce15c450c8
     */
    @GetMapping("/edit/{nurseId}")
    public String edit(@PathVariable("nurseId") String nurseId, ModelMap mmap) {
        YfDeptNurse yfDeptNurse = yfDeptNurseService.selectYfDeptNurseById(nurseId);
        mmap.put("yfDeptNurse", yfDeptNurse);
        return prefix + "/edit";
    }

    /**
     * 修改保存科室护士
     * 047ae6a5-e0cd-4242-b4f4-f762e1a73965
     */
    @RequiresPermissions("yf:nurse:edit")
    @Log(title = "科室护士", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(YfDeptNurse yfDeptNurse) {
        SysUser sysUser = ShiroUtils.getSysUser();
        yfDeptNurse.setUpdateId(sysUser.getUserId());
        yfDeptNurse.setUpdateBy(sysUser.getLoginName());
        return toAjax(yfDeptNurseService.updateYfDeptNurse(yfDeptNurse));
    }

    /**
     * 删除科室护士
     * 2b093315-a6b0-474f-a0b1-70584265aae0
     */
    @RequiresPermissions("yf:nurse:remove")
    @Log(title = "科室护士", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(yfDeptNurseService.deleteYfDeptNurseByIds(ids));
    }
}
